package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.product.ProductDirectoryListRequest;
import com.mes.cloud.api.dto.request.product.ProductDirectoryPageRequest;
import com.mes.cloud.api.dto.request.product.ProductDirectoryRequest;
import com.mes.cloud.api.dto.response.product.ProductDirectoryDto;
import com.mes.cloud.common.CommPager;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.service.ProductDirectoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author ysd
 * @email shaodong.yuan@pactera.com
 * @version 2019-08-20 16:23:41
 */
@Api(tags = "产品目录", value = "产品目录接口")
@RestController
@RequestMapping(value = "/productDirectory")
public class ProductDirectoryController  {

    private ProductDirectoryService productDirectoryService;

    @Autowired
    public ProductDirectoryController(ProductDirectoryService productDirectoryService) {
        this.productDirectoryService = productDirectoryService;
    }

    /**
     * 功能: 产品目录分页查询
     *
     * @param pageRequest
     * @return JsonResult<CommPager<ProductDirectoryDto>>
     */
    @ApiOperation(value = "产品目录分页查询", notes = "产品目录分页查询")
    @PostMapping(value = "/pageList")
    public JsonResult<CommPager<ProductDirectoryDto>> pageList(@Valid @RequestBody ProductDirectoryPageRequest pageRequest) {
        return productDirectoryService.pageList(pageRequest);
    }

    /**
     * 功能: 产品目录查询所有
     *
     * @param productDirectoryListRequest
     * @return JsonResult<List<ProductDirectoryDto>>
     */
    @ApiOperation(value = "产品目录查询所有", notes = "产品目录查询所有")
    @PostMapping(value = "/list")
    public JsonResult<List<ProductDirectoryDto>> list(@RequestBody ProductDirectoryListRequest productDirectoryListRequest) {
        return  productDirectoryService.list(productDirectoryListRequest);
    }

    /**
     * 功能: 编辑产品目录树
     *
     * @param id
     * @return JsonResult<List<ProductDirectoryDto>>
     */
    @ApiOperation(value = "编辑产品目录树", notes = "编辑产品目录树")
    @ApiImplicitParam(paramType = "Long", name = "id", value = "产品目录主键", required = true)
    @GetMapping(value = "updateTree/{id}")
    public JsonResult<List<ProductDirectoryDto>> updateTree(@PathVariable String id) {
        return  productDirectoryService.updateTree(id);
    }

    /**
     * 功能: 产品目录新增
     *
     * @param productDirectoryRequest
     * @return JsonResult
     */
    @ApiOperation(value = "产品目录新增", notes = "产品目录新增")
    @PostMapping(value = "/add")
    public JsonResult<ProductDirectoryDto> add(@Valid @RequestBody ProductDirectoryRequest productDirectoryRequest) {
        return productDirectoryService.add(productDirectoryRequest);
    }

    /**
     * 功能: 产品目录修改
     *
     * @param productDirectoryRequest
     * @return JsonResult
     */
    @ApiOperation(value = "产品目录修改", notes = "产品目录修改")
    @PostMapping(value = "/update")
    public JsonResult<ProductDirectoryDto> update(@Valid @RequestBody ProductDirectoryRequest productDirectoryRequest)  throws Exception {
        return productDirectoryService.update(productDirectoryRequest);

    }

    /**
     * 功能: 产品目录查看详情
     *
     * @param id
     * @return JsonResult
     */
    @ApiOperation(value = "产品目录查看详情", notes = "产品目录查看详情")
    @ApiImplicitParam(paramType = "Long", name = "id", value = "产品目录主键", required = true)
    @GetMapping(value = "get/{id}")
    public JsonResult<ProductDirectoryDto> get(@PathVariable String id) {
        return productDirectoryService.get(id);
    }

    /**
     * 功能: 产品目录禁用启用
     *
     * @param id
     * @param enableFlag
     * @return JsonResult
     */
    @ApiOperation(value = "产品目录禁用启用", notes = "产品目录禁用启用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true),
            @ApiImplicitParam(name = "enableFlag", value = "状态", required = true),
    })
    @GetMapping(value = "/updateEnableFlag/{id}/{enableFlag}")
    public JsonResult updateEnableFlag(@PathVariable String id, @PathVariable String enableFlag) {
        return productDirectoryService.updateEnableFlag(id, enableFlag);
    }
}
